import Vue from 'vue';
import Vuex from 'vuex';
import lodash from 'lodash';
import { getWebInfo } from '@/api/front';
Vue.use(Vuex)
const state = {
	webSiteInfo: {}
}
const actions = {
	//获取网站信息
	async queryWebInfo({ commit }) {
		let result = await getWebInfo().then(res => res.data);
		if (result.code == '0') {
			let datas = lodash.mapValues(lodash.keyBy(result.data || [], 'code'), item => {
				if (item.type === '1') {
					return item.value;
				} else if (item.type === '2') {
					let httpUrl = item.sysAttachment?.httpUrl;
					return httpUrl?.replaceIP();
				}
			});
			commit('SET_WEB_SITE_INFO', datas);
		} else {
			Promise.reject(new Error('faile'));
		}
	},

	//获取网站栏目数据
	async getWebColumnData() {

	}
}
const mutations = {
	SET_WEB_SITE_INFO: (state, d) => {
		state.webSiteInfo = d;
	}
}
export default { state, actions, mutations }